package com.ruoyi.project.property.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.project.property.domain.AddProperty;
import com.ruoyi.project.property.domain.LabProperty;
import com.ruoyi.project.property.service.ILabPropertyService;
import com.ruoyi.project.system.dict.domain.DictData;
import com.ruoyi.project.system.dict.service.IDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2019-11-16
 */
@Controller
@RequestMapping("labproperty")
public class LabPropertyController extends BaseController
{
    private String prefix = "system/property";

    @Autowired
    private ILabPropertyService labPropertyService;

    @Autowired
    private IDictDataService iDictDataService;

    @RequiresPermissions("system:property:view")
    @GetMapping()
    public String property(ModelMap map)
    {
        //獲取字典表中的資產類別
        List<DictData> dicts=iDictDataService.selectDictDataByType("property_type");
        //將數據加入到容器
        map.addAttribute("dictData",dicts);
        return prefix + "/property";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:property:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LabProperty labProperty)
    {
        System.out.println("lab:"+labProperty);
        startPage();
        List<LabProperty> list = labPropertyService.selectLabPropertyList(labProperty);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:property:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LabProperty labProperty)
    {
        List<LabProperty> list = labPropertyService.selectLabPropertyList(labProperty);
        ExcelUtil<LabProperty> util = new ExcelUtil<LabProperty>(LabProperty.class);
        return util.exportExcel(list, "property");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add(ModelMap map)
    {
        //查询实验室名称列表
        List<AddProperty> labs=new ArrayList<>();
        labs=labPropertyService.getAllLab();
        //将信息放入容器中
        map.addAttribute("labName",labs);

        //獲取字典表中的資產類別
        List<DictData> dicts=iDictDataService.selectDictDataByType("property_type");
        //將數據加入到容器
        map.addAttribute("dictData",dicts);
        //System.out.println(labs);
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:property:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LabProperty labProperty)
    {
        return toAjax(labPropertyService.insertLabProperty(labProperty));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        //查询实验室名称列表
        List<AddProperty> labs=new ArrayList<>();
        labs=labPropertyService.getAllLab();
        //将信息放入容器中
        mmap.addAttribute("labName",labs);

        //獲取字典表中的資產類別
        List<DictData> dicts=iDictDataService.selectDictDataByType("property_type");
        //將數據加入到容器
        mmap.addAttribute("dictData",dicts);
        LabProperty labProperty = labPropertyService.selectLabPropertyById(id);
        mmap.put("labProperty", labProperty);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:property:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LabProperty labProperty)
    {
        return toAjax(labPropertyService.updateLabProperty(labProperty));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:property:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(labPropertyService.deleteLabPropertyByIds(ids));
    }


}
